//
//  OJType.m
//  openJira
//
//  Created by Vincent Demay on 30/04/10.
//  Copyright 2010 Goojet. All rights reserved.
//

#import "OJType.h"


@implementation OJType

@synthesize name, description, lid, icon;


- (void) dealloc {
	[name release];
	[description release];
	[icon release];
	[super dealloc];
}


@end



///////////////////////// OJISSUELIST //////////////////////

@implementation OJTypeList

@synthesize types, delegate;

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}


- (void) getPriorities{
	[[OJConnector getDefault] getTypes:self];
}


////////////////////////// MANAGE RESPONSES ///////////////////
- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response{
	id fromResponse = [response  object];
	[types release];
	types = [[NSMutableDictionary alloc] init];
	
	for (int i=0; i<[fromResponse count]; i++) {
		OJType *type = [[OJType alloc] init];
		type.name = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"name"];
		type.description = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"description"];
		type.icon = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"icon"];
		type.lid = [[((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"id"] intValue];
		[types setObject:type forKey:[NSString stringWithFormat:@"%d",type.lid]];
		[type release];
	}
	
	[delegate object:self isReady:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response{
	[delegate object:self isReady:YES];
}

@end
